package com.blog.backend.controller;

import com.blog.backend.annotation.LoginAnno;
import com.blog.backend.req.ArticleListReq;
import com.blog.backend.req.EditArticleReq;
import com.blog.backend.req.InsertArticleReq;
import com.blog.backend.resp.ArticleResp;
import com.blog.backend.service.ArticlesService;
import com.blog.backend.utils.Result;
import com.blog.backend.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author fanggongsai
 * @description
 * @Date 2021-07-17
 */

@RestController
@Api(tags = "文章管理接口api")
public class ArticlesController {

    @Resource
    private ArticlesService articlesService;

    @PostMapping("/article/insertArticle")
    @LoginAnno
    @ApiOperation("新增文章")
    public Result<String> insertArticle(@RequestBody InsertArticleReq req){
        articlesService.insertArticle(req);
        return Result.success();
    }

    @PostMapping("/article/queryArticleList")
    @ApiOperation("查询文章列表")
    public Result<PageResult<ArticleResp>> queryArticleList(@RequestBody ArticleListReq req){
        PageResult page= articlesService.queryArticleList(req);
        return Result.success(page);
    }

    @GetMapping("/article/queryDetail")
    @LoginAnno
    @ApiOperation("查看文章详情")
    public Result<ArticleResp> queryDetail(@RequestParam("articleId") String articleId){
        ArticleResp resp= articlesService.queryDetail(articleId,null);
        return Result.success(resp);
    }

    @PostMapping("/article/editDetail")
    @LoginAnno
    @ApiOperation("编辑文章")
    public Result<String> editArticle(@RequestBody EditArticleReq req){
        articlesService.editArticle(req);
        return Result.success();
    }

    @GetMapping("/article/deleteArticle")
    @LoginAnno
    @ApiOperation("删除文章")
    public Result<String> deleteArticle(@RequestParam("articleId") String articleId){
        articlesService.deleteArticle(articleId);
        return Result.success();
    }
}
